from fastapi import Request
from typing import List
from core.curd import QueryWrapper, IBaseService
from app.dao.system import SysDictTypeDao, SysDictDataDao
from app.entity.system import SysDictData, SysDictType


class SysDictTypeService(IBaseService):

    async def select_by_query(self,queryWrapper:QueryWrapper) -> SysDictType:
        return await self.dao.select_by_query(queryWrapper)

    async def get_sql_data(self, sql: str):

        total, rows = await self.dao.get_sql_data(sql)

        return total, rows

    async def delete_dict_type(self, ids:List[int]):
        await self.dao.delete_dict_type(ids)

    async def get_all_dict_type(self):
        return await self.dao.get_all_dict_type()
    @classmethod
    async def instance(cls, req: Request):
        inst = cls()
        inst.dao = await SysDictTypeDao.instance(req, SysDictType)
        return inst


class SysDictDataService(IBaseService):

    @classmethod
    async def instance(cls, req: Request):
        inst = cls()
        inst.dao = await SysDictDataDao.instance(req, SysDictData)
        return inst
